import axios from '@/libs/api.request'

/**
 * 登录接口
 * @param userName
 * @param password
 * @param validCode
 * @param validCodeId
 * @returns {*}
 */
export const login = ({ userName, password, validCode, validCodeId }) => {
  const data = {
    username: userName,
    password: password,
    code: validCode,
    uuid: validCodeId
  }
  return axios.request({
    url: '/system/login',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

/**
 * 获取图形验证码接口
 * @returns {*}
 */
export const getCodeImg = () =>{
  return axios.request({
    url: '/system/getCaptcha?type=char',
    method: 'get'
  })
}

/**
 * 获取用户信息接口（登陆后）
 * @returns {*}
 */
export const getUserInfo = () => {
  return axios.request({
    url: '/system/getUserInfo',
    method: 'get'
  })
}


/**
 * 获取动态路由接口
 * @returns {*}
 */
export const initMenu = () => {
  return axios.request({
    url: '/system/initMenu',
    method: 'post'
  })
}

export const logout = () => {
  return axios.request({
    url: '/system/logout',
    method: 'get'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
